package com.ecfront.test.dao;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.ecfront.dao.GoodsBrandDAO;
import com.ecfront.dao.GoodsDAO;
import com.ecfront.dao.GoodsSortDAO;
import com.ecfront.pojo.Goods;
import com.ecfront.pojo.GoodsBrand;
import com.ecfront.pojo.GoodsSort;
import com.ecfront.pojo.Supplier;

import junit.framework.TestCase;

public class testGoods extends TestCase {
	private static final GoodsDAO goodsDao = (GoodsDAO)SpringUtilTest.getBean("GoodsDAO");
	private static final GoodsBrandDAO goodsBrandDao = (GoodsBrandDAO)SpringUtilTest.getBean("GoodsBrandDAO");
	private static final GoodsSortDAO goodsSortDAO = (GoodsSortDAO)SpringUtilTest.getBean("GoodsSortDAO");
	//保存测试
	public void testSave(){
		Goods goods = new Goods();
		
		GoodsBrand gb1 = goodsBrandDao.findById(1);
		goods.setGb(gb1);
		
		GoodsSort gs1 = goodsSortDAO.findById(1);
		goods.setGs(gs1);
		
		goods.setHits(0);
		goods.setImgUrl("物品.jpg");
		goods.setInfo("好东西");
		goods.setIsGuarantee(0);
		goods.setIsRecommend(0);
		goods.setIsShow(1);
		goods.setName("赵科牌电脑");
		goods.setPrice(1000.0);
		goods.setRestCount(100);
		goods.setTradePrice(800.0);
		
		Supplier supplierId = new Supplier();
		supplierId.setId(1);
		goods.setSupplierId(supplierId);
		
		goodsDao.save(goods);
		
	}
	//FindAll测试
	public void testFindAll(){
		List list = goodsDao.findAll();
		for(Iterator iter = list.iterator();iter.hasNext();){
			Goods goods = (Goods)iter.next();
			System.out.println(goods.getName());
		}
	}
	//FindById测试
	public void testFindById(){
		Goods goods = goodsDao.findById(2);
		System.out.println(goods.getName());
		
		System.out.println(goods.getGb().getName());
		System.out.println(goods.getGs().getName());
		System.out.println(goods.getSupplierId().getName());
	}
	//指定Property查找
	public void testProperty(){
		List list = goodsDao.findByGtitle("赵科牌电脑");
		for(Iterator iter = list.iterator();iter.hasNext();){
			Goods goods = (Goods)iter.next();
			System.out.println(goods.getName());
		}
	}
	//删除测试
	public void testDel(){
		Goods goods = new Goods();
		goods.setId(3);
		goodsDao.delete(goods);
	}
}
